Common CLI behavior#1198
Conversation
865f053 to
6a97616
Compare
6a97616 to
6ed2089
Compare
|
I ran the release in dry-run but it stopped at the first step: https://github.com/silx-kit/pymca/actions/runs/22523143704 . In dry-run we can skip the version checks I think. |
I think you've started "force" not a "dry-run". I started the dry-run, it skips the version check. Or maybe GitHub again get crazy - actions are behaving weirdly in the last ~month... |
|
I find very weird to have a main function that can be called by anybody instantiating a QApplication I would either:
|
We do that for all our CLI's.
Allows things to be testable. |
Thank you for taking things out of context. Where the You should not try to instantiate a QApplication inside something not protected by |
You are welcome. |
|
I think you are missing the point that you can have those |
Can you give an example? These main functions take parsed and validated CLI arguments so that would be a surprising use case. |
I can imagine to instantiate a QApplication and to loop for all the modules to call their |
aa0444d to
3556ad8
Compare
|
Probably #1183 should be closed without merge - even if it is OK there is no point in it after this one. |
Closes #1141
Two new modules for common behavior across all PyMca applications:
PyMca5.PyMcaGui.PyMcaAppInit: common behavior for multiprocessing, Qt, HDF5, matplotlib, logging.Manage common calls at these stages of the application launch:
PyMca5.PyMcaMisc.CliUtils: common CLI behavior in terms of logging, common arguments.Uses
argparseinstead ofgetoptwhich provides proper--helpfor users.The docstring of the two modules show the usage pattern.
Currently we have 28 CLI's of which 20 are Qt apps. There are many more files with a
__main__, many of which usingsys.argvdirectly, but I only handled the ones that already had an explicit CLI by usinggetoptorargparse.In addition I added unit tests for the CLI:
python -m PyMca5.tests.CliTestMain CLI as an example
pymca --help usage: pymca [-h] [--debug DEBUG] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--version] [--qt {5,6}] [--binding {pyqt5,pyqt6,pyside2,pyside6}] [--nativefiledialogs NATIVEFILEDIALOGS] [-b {matplotlib,mpl,gl,opengl,glut,osmesa,mesa,silx,silx-mpl,silxmpl,silx-gl,silxgl}] [--spec SPEC] [--shm SHM] [--fresh] [--profiling] [--test] [files ...] Main PyMca GUI positional arguments: files Optional list of data files to open (default: None) options: -h, --help show this help message and exit --debug DEBUG Enable debug mode (default: 0) --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL} Logging level (default: WARNING) --version Show version and exit (default: False) --qt {5,6} Force Qt version (default: None) --binding {pyqt5,pyqt6,pyside2,pyside6} Qt binding (default: None) --nativefiledialogs NATIVEFILEDIALOGS Use native file dialogs (default: None) -b {matplotlib,mpl,gl,opengl,glut,osmesa,mesa,silx,silx-mpl,silxmpl,silx-gl,silxgl}, --backend {matplotlib,mpl,gl,opengl,glut,osmesa,mesa,silx,silx-mpl,silxmpl,silx-gl,silxgl} The plot backend to use: Matplotlib, OpenGL 2.1 (requires appropriate OpenGL drivers), or Off-screen Mesa OpenGL software pipeline (requires OSMesa library). (default: mpl) --spec SPEC Spec file (default: None) --shm SHM Shared memory spec (default: None) --fresh, -f Clear configuration (default: False) --profiling Run main loop under profiler (default: False) --test Run unit tests (default: False)